#!/bin/bash

#
#
#
#
#version 1 
# Requirement : ORACLE_HOME and ORACLE_BASE be defined 
#
#
#
#
#
#
#



script_version="script version 1"
echo $script_version

if [ ! -d /var/log/munsoft/ ]
 then
  mkdir /var/log/munsoft/
  chmod 777 /var/log/munsoft/
fi

b_date=`date +%d%m%y`
starttime=`date`

export PATH=$PATH:$ORACLE_HOME/bin:/usr/lib

echo 'copy ProIV programs in process '

cd /

scp -r /u1/proclassic/*.pro /u1/muntest
scp -r /u1/proclassic/gls /u1/muntest
scp -r /u1/proclassic/pccash /u1/muntest
scp -r /u1/proclassic/pcin /u1/muntest
scp -r /u1/proclassic/pcout /u1/muntest
scp -r /u1/proclassic/progs /u1/muntest
scp -r /u1/proclassic/proisam /u1/muntest
scp -r /u1/proclassic/pro-ora /u1/muntest

chown -R muntestg:oinstall /u1/muntest
chmod 775 /u1/muntest/*.pro

par1=$1

if [ $par1 ]; then
echo ""

else
par1="normal"
fi


if [ $par1 = 'initial' ]; then

su - oracle -c "expdp munpro/munpro@MUNPRO3i dumpfile=expdp_munpro_MUNPRO3i.dmp logfile=expdp_munpro_MUNPRO3i.log schemas=munpro REUSE_DUMPFILES=YES EXCLUDE=DB_LINK"
mv -f $ORACLE_BASE/admin/MUNPRO3i/dpdump/expdp_munpro_MUNPRO3i.dmp $ORACLE_BASE/admin/MUNTEST3i/dpdump/
su - oracle -c "impdp muntest/muntest@MUNTEST3i dumpfile=expdp_munpro_MUNPRO3i.dmp logfile=impdp_muntest_MUNTEST3i.log remap_schema=munpro:muntest TABLE_EXISTS_ACTION=REPLACE"

else

su - oracle -c "expdp munpro/munpro@MUNPRO3i dumpfile=expdp_munpro_MUNPRO3i.dmp logfile=expdp_munpro_MUNPRO3i.log schemas=munpro REUSE_DUMPFILES=YES INCLUDE=TABLE,VIEW,PROCEDURE"
mv -f $ORACLE_BASE/admin/MUNPRO3i/dpdump/expdp_munpro_MUNPRO3i.dmp $ORACLE_BASE/admin/MUNTEST3i/dpdump/
/u1/scripts/drop_ageing_procedures.sh muntest

rm -f /tmp/DROP_ALL_VIEWS.SQL

su - oracle -c "sqlplus munpro/munpro@MUNPRO3i <<EOF

set echo off
set feedback off
set linesize 1000
set pagesize 0
set sqlprompt ''
set trimspool on
spool /tmp/DROP_ALL_VIEWS.SQL

SELECT 'drop view '||VIEW_NAME||';' FROM ALL_VIEWS WHERE OWNER = 'MUNPRO';

prompt exit;
exit;

<<EOF"

su - oracle -c "sqlplus muntest/muntest@MUNTEST3i <<EOF
@/tmp/DROP_ALL_VIEWS.SQL
quit
<<EOF"


su - oracle -c "impdp muntest/muntest@MUNTEST3i dumpfile=expdp_munpro_MUNPRO3i.dmp logfile=impdp_muntest_MUNTEST3i.log remap_schema=munpro:muntest TABLE_EXISTS_ACTION=REPLACE"
rm -f /tmp/DROP_ALL_VIEWS.SQL

fi

endtime=`date`

echo "============================================== "
echo "		Copy Live To Test COMPLETE"
echo "		START TIME  : $starttime"
echo "		END TIME    : $endtime"
echo "============================================== "

